//
//  LSPushMgr.m
//  LiveStar
//
//  Created by 漪珊 on 2016/12/31.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "LSPushMgr.h"

@implementation LSPushMgr
- (void)getPushUrlWithGroupID:(NSString *)groupid hander:(RequestPushUrlHandle)handle {
    NSDictionary *dic = @{
                          @"udid":User_ID,
                          @"token":TOKEN
                          };
    NSString *urlString = [TEST_URL stringByAppendingString:kStarLive];
    [NetworkTools postReqeustWithParams:dic UrlString:urlString successBlock:^(id responseObject) {
        //如果返回code=200 标示成功 其他标示失败
        if ([KString(responseObject[@"code"]) isEqualToString:@"200"]) {
            NSString *urlString = responseObject[@"data"][@"rtmp"];//推流URL
            NSString *roomid = responseObject[@"data"][@"channel"];
            NSString *chatgroupid = responseObject[@"data"][@"channel"];
            handle(nil,urlString,roomid,chatgroupid);
        }
    } failureBlock:^(NSError *error) {
        handle(error,nil,nil,nil);
    } showHUD:NO];
}

- (void)changeLiveStatusWithRoomID:(NSString *)roomid
                        Chatroomid:(NSString *)chatroomid
                            Status:(LSLiveStatus)status
                            Handle:(PushMgrCompleteHandle)handle {
    if (roomid == nil) {
        dispatch_async(dispatch_get_main_queue(), ^{
//            handler(kError_InvalidParam);
            
        });
        return;
    }
    NSDictionary *dic = @{@"udid":User_ID,
                          @"token":TOKEN,
                          @"channel":roomid,
                          @"group":chatroomid,
                          @"status":@(status)
                          };
    NSString *urlString = [TEST_URL stringByAppendingString:kRoomStatus];
    [NetworkTools postReqeustWithParams:dic UrlString:urlString successBlock:^(id responseObject) {
        NSString *code = KString(responseObject[@"code"]);
        handle(nil,code);
    } failureBlock:^(NSError *error) {
        handle(error,@"failed");
    } showHUD:NO];
}
@end
